import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
import {CONSTANT} from "../../service/constant.service";
import {TitleCpt} from "../../lib/title/title.component";
import {BalanceService} from "../../service/balance.service";
import {CheckStandModel} from "../../model/checkstand.model";
import {LocalStorage} from "../../app.local-storage";
import {ROUTE} from "../../service/route.service";
declare var $:any;
@Component({
  selector: 'app-recharge-modal',
  templateUrl: './recharge-modal.component.html',
  styleUrls: ['./recharge-modal.component.scss']
})
export class RechargeModalComponent implements OnInit {
  @Input('showModal') public isModalShown: boolean = false;
  @Output('modalClose') public modalClose = new EventEmitter();

  payType:any={
    alipay:2,
    weChat:1
  }
  money:number;
  constructor(private route:ROUTE,private constant:CONSTANT,private balanceService:BalanceService,private localStorage:LocalStorage) { }
  rechargeTitleCptList:Array<TitleCpt> = this.constant.genRechargeTitleCptList();
  ngOnInit() {
  }

  public showModal(): void {
    this.isModalShown = true;
  }

  public onHidden(): void {
    this.isModalShown = false;
  }
  recharge(){
    let value:any = $('input[name=pay]:checked').val();

    let reqData = {
      money:this.money,
      rechargeType:3
    }
    this.balanceService.recharge(reqData,v=>{
      console.log(v)
      let checkstand = new CheckStandModel(v.rechargeSn,v.content,v.money,v.id,'personal/mybalance')
      checkstand.setBalancePay();
      this.localStorage.setObject('checkstand',checkstand);
      this.route.goConfirmPaymentView(v.rechargeSn);
    });
  }


}
